package com.xja.controller;/**
 * @className: MenuController
 * @description: TODO 类描述
 * @author: wkx
 * @date: 2022/4/11
 **/


import com.xja.pojo.Menu;
import com.xja.service.MenuService;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @ClassName : MenuController  //类名

 * @Author : Lenovo //作者
 * @Date: 2022/4/11  15:37
 */
@Controller
@RequestMapping("menu")
public class MenuController {
    private Logger logger = LoggerFactory.getLogger(MenuController.class);
    @Reference(url = "dubbo://localhost:20882")
    private MenuService menuService;

    @RequestMapping("toMenu")
    public String toRole(Model model,@RequestParam(value = "page",defaultValue = "1") Integer page, @RequestParam(value = "parent_id",defaultValue = "0") Integer parent_id){
        logger.info("跳转至菜单管理页面");
        List<Menu> menuList = menuService.getMenuList(parent_id, null);


        model.addAttribute("menuList",menuList);
        model.addAttribute("parent_id",parent_id);
        return "menu";
    }

    @RequestMapping("addMenu")
    public String addMenu(Menu menu){
        logger.info("添加菜单");

        menuService.addMenu(menu);
        return "redirect:/menu/toMenu";
    }
    @RequestMapping("updateMenu")
    public String updateMenu(Menu menu){
        logger.info("修改菜单");

        menuService.updateMenu(menu);
        return "redirect:/menu/toMenu";
    }
    @RequestMapping("toAddMenu")
    public String toAddMenu(Integer parent_id,Model model){
        logger.info("跳转到添加菜单页面");

        model.addAttribute("parent_id",parent_id);
        return "addMenu";
    }
    @RequestMapping("toUpdateMenu")
    public String toUpdateMenu(Integer mid,Model model){
        logger.info("跳转到修改菜单页面");
        Menu menu = menuService.getMenuByMid(mid);
        model.addAttribute("menu",menu);
        return "updateMenu";
    }
}
